import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * User: Ratuil
 * Date: 21.02.13
 * Time: 12:08
 * To change this template use File | Settings | File Templates.
 */
public class StrWordInvert {
    public static void main(String[]args){
        new StrWordInvert().run();
    }
    public StrWordInvert(){
        str="abc def ghi".getBytes();

    }
    public void run(){
        //32 - bytecode of "space"
        str="abc def ghi".getBytes();
        int i=0;                                  //increment iterator of the string
        int j=str.length-1;                                  //decrement iterator of the string
        for(byte itr:str)System.out.print(itr + " ");


        while(i!=j){                        //process while iterators not reach each other
            if(str[i]==32&&str[j]==32){i++;j--;continue;}
            if(str[i]==32&&str[j]!=32){i++;continue;}
            if(str[i]!=32&&str[j]==32){j++;continue;}
            if(str[i]!=32&&str[j]!=32){swap(i,j);i++;j--;continue;}
        }
        i=0;j=0;
        while(i!=str.length){
            if(str[i]==32){
                for(int k=0;j<i;j++,k++)swap(j,i-k-1);
            }
            i++;
        }
        System.out.print("\n");
        for(byte itr:str)System.out.print(itr+" ");
    }
    private void swap(int i,int j){
        byte buf=str[i];
        str[i]=str[j];
        str[j]=buf;
    }
    byte[]str;                              //data string to process
}
